﻿namespace GuessTheAnswer.Model.Subject;


/// <summary>
/// 多选题目
/// </summary>
public class MultiChoiceSubject : ISubject
{
    public string TypeName => "多选题";

    public IAnswerRound CreateRound() => new MultiChoiceRound();
}


internal class MultiChoiceRound : IAnswerRound
{
    /// <summary>
    /// 结果列表
    /// </summary>
    private static readonly string[] ResultList = new string[] { "A", "B", "C", "D", "E", "F" };

    private List<int> CorrectId { get; } = new() { 0 };

    public bool IsCorrect { get; private set; } = false;

    public int RoundNumber { get; private set; } = 1;

    public void Correct() => IsCorrect = true;

    public void Last() { }

    public void Next()
    {
        if (RoundNumber >= ResultList.Length)
        {
            throw new Exception("回合超出可猜测范围");
        }

        if(IsCorrect == false)
        {
            CorrectId.RemoveAt(CorrectId.Count - 1);
        }

        CorrectId.Add(RoundNumber);

        RoundNumber++;
        IsCorrect = false;
    }

    public string RoundAnswer()
    {
        return string.Join("", from i in CorrectId select ResultList[i]);
    }
}